#include "VofaFireData.h"
#include <stdlib.h>

//
#include "stm32f1xx_hal.h"
#include "dma.h"
#include "usart.h"

#define USE_UART huart3
#define TIMEOUT 1000
//

static uint8_t RawDataString[16] = {0};
static float Data = 0;

static void UARTTransmit(uint8_t *data)
{
    HAL_UART_Transmit_DMA(&USE_UART, (uint8_t *)data, strlen(data));
}

static void UARTReceive()
{
    HAL_UARTEx_ReceiveToIdle_DMA(&USE_UART, RawDataString, sizeof(RawDataString));
    __HAL_DMA_DISABLE_IT(USE_UART.hdmarx, DMA_IT_HT);
}

/**
 * @brief
 *
 * @param str 需要发送的字符串
 */
void VofaSend(uint8_t *str)
{
    UARTTransmit(str);
}

void VofaInit(void)
{
    UARTReceive();
}

float VofaGetData(void)
{
    return Data;
}

extern float setPressure;
void VofaGetCallback(void)
{
    uint8_t pEnd[16];
    Data = strtof(RawDataString, pEnd);
    setPressure = Data;
    UARTReceive();
}
